﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Text.RegularExpressions;
public class Recyle : MonoBehaviour {

    //对象池的命名规则为生成对象的名字截（0-name.length-1)
    [SerializeField]
    private string poolName;
   void Start()
   {
        poolName=Regex.Replace(this.gameObject.name, @"\d","");
   }
    void OnEnable () {
       
        StartCoroutine ("RecyleObject");
    }
    IEnumerator RecyleObject () {
        yield return new WaitForSeconds (2);
        ObjectPool.Recyle (poolName, this.gameObject.name,RecyleAction);

    }
    //回收调用
    void RecyleAction () {
        Debug.Log ("开始回收");
        this.GetComponent<Rigidbody> ().velocity = Vector3.one;
        this.GetComponent<Rigidbody> ().angularVelocity = Vector3.zero;
        this.transform.localPosition = Vector3.zero;
        this.gameObject.SetActive (false);
    }
}